export * from './const';
/**
 * 获取主vscode-file://vscode-app/d:/Apps/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-browser/workbench/workbench.html键字段名称，如果没有主键则返回第一个字段名称
 */
export const getPrimaryFieldName = (fields:Field[]): string => {
    if (fields.length === 0) return 'ID';
    // 查找主键字段
    const primaryField = fields.find(field => field.isPrimary);
    if (primaryField) {
      return primaryField.name;
    }
    // 如果没有主键，返回第一个字段
    return fields[0].name;
  };

/**
 * 获取记录的主要显示值
 */
export const getFieldValue = (
  record: DocRecord, 
  fieldName: string, 
): string => {
  
  const value = record.fields[fieldName];
  
  if (value === null || value === undefined || value === '') {
    return '';
  }
  
  let displayValue: string;
  
  // 如果是对象类型的值，尝试提取文本
  if (typeof value === 'object' && value !== null) {
    displayValue = JSON.stringify(value);
  } else {
    displayValue = String(value);
  }
  return displayValue;
};


export const isEmptyStr = (str: string | null | undefined): boolean => { 
  return str === null || str === undefined || str === ''; //str.replace(/["'\[\],]/g, '').length===0 || str.trim() === '';
}

export const isEmpty = (str: any | null | undefined): boolean => { 
  return str === null || str === undefined ||str ==='' ; //str.replace(/["'\[\],]/g, '').length===0 || str.trim() === '';
}

export const isEmptyArr = (arr: string[] | null | undefined): boolean => { 
   return arr === null || arr === undefined || arr.length===0 || arr.every(item=>isEmptyStr(item));
  // return str === null || str === undefined ||str ==='' ; //str.replace(/["'\[\],]/g, '').length===0 || str.trim() === '';
}